package com.pospi.pai.yunpos.cash;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kyleduo.switchbutton.SwitchButton;
import com.lany.sp.SPHelper;
import com.maning.library.MClearEditText;
import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.view.listener.OnCreateBodyViewListener;
import com.pospi.callbacklistener.HttpCallBackListener;
import com.pospi.dao.GoodsDao;
import com.pospi.dto.GoodsDto;
import com.pospi.dto.ImgeBeen;
import com.pospi.http.HttpConnection;
import com.pospi.img.DownLoadImageService;
import com.pospi.img.ImageDownLoadCallBack;
import com.pospi.pai.yunpos.R;
import com.pospi.pai.yunpos.base.Base2Activity;
import com.pospi.pai.yunpos.been.PermitonBeen;
import com.pospi.pai.yunpos.bh.SupAotoListActivity;
import com.pospi.pai.yunpos.bh.SupGoodsListActivity;
import com.pospi.pai.yunpos.caigou.CgshListActivity;
import com.pospi.pai.yunpos.caigou.CountsListActivity;
import com.pospi.pai.yunpos.caigou.OverFlowListActivity;
import com.pospi.pai.yunpos.caigou.PdListActivity;
import com.pospi.pai.yunpos.caigou.ReceiveBillListActivity;
import com.pospi.pai.yunpos.caigou.RefundBillListActivity;
import com.pospi.pai.yunpos.diaob.DboChaYListActivity;
import com.pospi.pai.yunpos.diaob.DboOutListActivity;
import com.pospi.pai.yunpos.diaob.DboReceiveListActivity;
import com.pospi.pai.yunpos.diaob.PsChaYListActivity;
import com.pospi.pai.yunpos.diaob.PsOutListActivity;
import com.pospi.pai.yunpos.diaob.PsReceiveListActivity;
import com.pospi.pai.yunpos.login.Constant;
import com.pospi.pai.yunpos.login.UserLoginActivity;
import com.pospi.pai.yunpos.more.LockActivity;
import com.pospi.pai.yunpos.more.LsjChangeActivity;
import com.pospi.pai.yunpos.more.PopChangeActivity;
import com.pospi.pai.yunpos.more.ScaleGoodsActivity;
import com.pospi.pai.yunpos.more.ScaleMangerActivity;
import com.pospi.pai.yunpos.more.StatisticsActivity;
import com.pospi.pai.yunpos.report.CgGoodsReportActivity;
import com.pospi.pai.yunpos.report.DbGoodsReportActivity;
import com.pospi.pai.yunpos.report.GoodsReportActivity;
import com.pospi.pai.yunpos.report.InventorySearchActivity;
import com.pospi.pai.yunpos.report.JxcReportActivity;
import com.pospi.pai.yunpos.report.KhReportActivity;
import com.pospi.pai.yunpos.report.PdGoodsReportActivity;
import com.pospi.pai.yunpos.report.PsGoodsReportActivity;
import com.pospi.pai.yunpos.report.SaleCateReportActivity;
import com.pospi.pai.yunpos.report.StoreReportActivity;
import com.pospi.pai.yunpos.report.SyyGoodsReportActivity;
import com.pospi.pai.yunpos.report.SyyOrderReportActivity;
import com.pospi.pai.yunpos.report.SyyPayReportActivity;
import com.pospi.pai.yunpos.report.SyySaleReportActivity;
import com.pospi.pai.yunpos.report.XsChartReportActivity;
import com.pospi.pai.yunpos.report.XsColumReportActivity;
import com.pospi.pai.yunpos.report.XsPiReportActivity;
import com.pospi.pai.yunpos.report.YWReportActivity;
import com.pospi.pai.yunpos.util.LoadingDialog;
import com.pospi.pai.yunpos.util.LogUtil;
import com.pospi.pai.yunpos.util.PermitionUtil;
import com.pospi.pai.yunpos.util.UnionConfig;
import com.pospi.pai.yunpos.vip.VipActivity;
import com.pospi.pai.yunpos.xs.OutBillListActivity;
import com.pospi.pai.yunpos.xs.SaleListActivity;
import com.pospi.util.AidlUtil;
import com.pospi.util.App;
import com.pospi.util.Sava_list_To_Json;
import com.pospi.util.SumiUtil;
import com.zzti.fengyongge.imagepicker.PhotoSelectorActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by acer on 2018/8/21.
 */

public class MenuActivity extends Base2Activity {
    @Bind(R.id.ll_bb)
    LinearLayout ll_bb;
    @Bind(R.id.ll_yw)
    LinearLayout ll_yw;
    @Bind(R.id.ll_th)
    LinearLayout ll_th;
    @Bind(R.id.ll_hy)
    LinearLayout ll_hy;
    @Bind(R.id.ll_sz)
    LinearLayout ll_sz;

    @Bind(R.id.tv_bb)
    TextView tv_bb;
    @Bind(R.id.tv_yw)
    TextView tv_yw;
    @Bind(R.id.tv_th)
    TextView tv_th;
    @Bind(R.id.tv_hy)
    TextView tv_hy;
    @Bind(R.id.tv_sz)
    TextView tv_sz;

    @Bind(R.id.iv_bb)
    ImageView iv_bb;
    @Bind(R.id.iv_yw)
    ImageView iv_yw;
    @Bind(R.id.iv_th)
    ImageView iv_th;
    @Bind(R.id.iv_hy)
    ImageView iv_hy;
    @Bind(R.id.iv_sz)
    ImageView iv_sz;
    @Bind(R.id.gridview_main)
    GridView gridview_main;
    @Bind(R.id.setting)
    LinearLayout setting;
    @Bind(R.id.switch_img_mode)
    SwitchButton switch_img_mode;
    @Bind(R.id.rb_device)
    RadioButton rb_device;
    @Bind(R.id.rb_scale_sg)
    RadioButton rb_scale_sg;
    @Bind(R.id.ll_xs)
    LinearLayout ll_xs;
    @Bind(R.id.tv_xs)
    TextView tv_xs;
    @Bind(R.id.iv_xs)
    ImageView iv_xs;

    @Bind(R.id.tv_vertion)
    TextView tv_vertion;
    @Bind(R.id.tv_phone)
    TextView tv_phone;
    @Bind(R.id.tv_adress)
    TextView tv_adress;
    @Bind(R.id.tv_shop)
    TextView tv_shop;
    @Bind(R.id.tv_syy)
    TextView tv_syy;
    @Bind(R.id.tv_sbh)
    TextView tv_sbh;
    @Bind(R.id.ll_union)
    LinearLayout ll_union;
    @Bind(R.id.tv_merchantCode)
    TextView tv_merchantCode;
    @Bind(R.id.tv_terminalCode)
    TextView tv_terminalCode;

    @Bind(R.id.tv_dzc_num)
    TextView tv_dzc_num;
    @Bind(R.id.tv_dzc_name)
    TextView tv_dzc_name;
    @Bind(R.id.tv_dzc_ip)
    TextView tv_dzc_ip;
    @Bind(R.id.tv_dzc_xh)
    TextView tv_dzc_xh;


    private List<ImgeBeen> urlList = new ArrayList<>();
    private PermitonBeen permiton;
    private MClearEditText et_sh_code;
    private MClearEditText et_zd_code;
    private EditText et_num;
    private EditText et_name;
    private EditText et_ip;
    private EditText et_xh;
    private MClearEditText et_old_pwd;
    private MClearEditText et_new_pwd;
    private MClearEditText et_new2_pwd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentLayout(R.layout.activity_menu);
        ButterKnife.bind(this);
        permiton = new PermitionUtil().getPermiton();
        setTitle("菜单");
        setting.setVisibility(View.GONE);
        init("ls");
        rb_device.setChecked(true);
        tv_vertion.setText("版本信息：" + getVersionName());
        tv_phone.setText("联系电话");
        tv_shop.setText("店铺：" + SPHelper.getInstance().getString(Constant.STORE_NAME));
        tv_syy.setText("收银员：" + SPHelper.getInstance().getString(Constant.USER_GH));
        tv_adress.setText("版权信息：" + "Copyright©2018 POSPI");
        tv_sbh.setText("设备号：" + (getSN().isEmpty() ? getAndroidId() : getSN()));
        SPHelper.getInstance().putString(Constant.SCALE_MODE, Constant.SCALE_SG);
        ll_xs.setBackgroundColor(getResources().getColor(R.color.WhiteSmoke));
        tv_xs.setTextColor(getResources().getColor(R.color.bule2));
        iv_xs.setImageResource(R.drawable.icon_cd_go_selected);
        switch_img_mode.setChecked(SPHelper.getInstance().getBoolean(Constant.MODE_IMG, false));
        switch_img_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
                new AlertDialog.Builder(MenuActivity.this)
                        .setTitle("提示")
                        .setMessage("是否切换")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SPHelper.getInstance().putBoolean(Constant.MODE_IMG, isChecked);
                                startActivity(PointActivity.class);
                                MenuActivity.this.finish();

                            }
                        }).setNegativeButton("放弃", null).show();

            }
        });
        tv_terminalCode.setText("终端号：" + SPHelper.getInstance().getString(UnionConfig.TERMINALCODE, ""));
        tv_merchantCode.setText("商户号：" + SPHelper.getInstance().getString(UnionConfig.MERCHANTCODE, ""));
        tv_dzc_ip.setText("IP："+SPHelper.getInstance().getString(Constant.DZC_IP, ""));
        tv_dzc_name.setText("名称："+SPHelper.getInstance().getString(Constant.DZC_NAME, ""));
        tv_dzc_num.setText("编号："+SPHelper.getInstance().getString(Constant.DZC_NUM, ""));
        tv_dzc_xh.setText("型号："+SPHelper.getInstance().getString(Constant.DZC_XH, ""));

    }

    @OnClick({R.id.ll_bb, R.id.ll_yw,
            R.id.ll_sz, R.id.tv_splk,  R.id.ll_xs,
            R.id.ll_refresh, R.id.ll_exsit,  R.id.ll_union, R.id.ll_dzc,})
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.ll_dzc://电子秤管理
                showdzc();
                break;
            case R.id.ll_union://银联配置
                showyl();
                break;
            case R.id.ll_exsit:
                new android.app.AlertDialog.Builder(this)
                        .setTitle("提示")
                        .setMessage("是否退出登录")
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SPHelper.getInstance().putBoolean("login", false);
                                startActivity(new Intent(MenuActivity.this, UserLoginActivity.class));
                                Sava_list_To_Json.clearGoodsMsg(MenuActivity.this);
                                new LogUtil().save(Constant.LOG_EXSIT);
                                finish();
                            }
                        })
                        .setNegativeButton("取消", null).show();
                break;
            case R.id.ll_refresh:
//                urlList.clear();
//                urlList.add(new ImgeBeen("01", "https://ws1.sinaimg.cn/large/610dc034ly1fgbbp94y9zj20u011idkf.jpg"));
//                urlList.add(new ImgeBeen("02", "https://ws1.sinaimg.cn/large/610dc034ly1fgdmpxi7erj20qy0qyjtr.jpg"));
//                for (ImgeBeen s : urlList) {
//                    onDownLoad(s);
//                }
                new AlertDialog.Builder(this)
                        .setTitle("提示")
                        .setMessage("是否更新数据？")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                downGoods();
                            }
                        }).setNegativeButton("取消", null).show();
                break;
            case R.id.ll_xs://零售
                init("ls");
                setbgNor();
                changeBg(view);
                tv_xs.setTextColor(getResources().getColor(R.color.bule2));
                iv_xs.setImageResource(R.drawable.icon_cd_go_selected);
                gridview_main.setVisibility(View.VISIBLE);
                setting.setVisibility(View.GONE);
//                new SumiUtil(this).sendImgsMenu();

                break;
            case R.id.tv_splk:
                startActivity(new Intent(this, LockActivity.class));
                finish();
                break;
            case R.id.ll_bb:
                init("bb");
                setbgNor();
                changeBg(view);
                tv_bb.setTextColor(getResources().getColor(R.color.bule2));
                iv_bb.setImageResource(R.drawable.icon_cd_go_selected);
                gridview_main.setVisibility(View.VISIBLE);
                setting.setVisibility(View.GONE);
                break;
            case R.id.ll_yw:
                init("yw");
                setbgNor();
                changeBg(view);
                tv_yw.setTextColor(getResources().getColor(R.color.bule2));
                iv_yw.setImageResource(R.drawable.icon_cd_go_selected);
                gridview_main.setVisibility(View.VISIBLE);
                setting.setVisibility(View.GONE);
                break;
            case R.id.ll_sz:
                if (!permiton.isCanSz()) {
                    Toast.makeText(this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                    return;
                }

                setbgNor();
                changeBg(view);
                tv_sz.setTextColor(getResources().getColor(R.color.bule2));
                iv_sz.setImageResource(R.drawable.icon_cd_go_selected);
                gridview_main.setVisibility(View.GONE);
                setting.setVisibility(View.VISIBLE);
                break;
        }
    }

    private void changeBg(View view) {
        view.setBackgroundColor(getResources().getColor(R.color.WhiteSmoke));


    }

    private void setbgNor() {
        ll_bb.setBackgroundColor(getResources().getColor(R.color.white));
        ll_yw.setBackgroundColor(getResources().getColor(R.color.white));
        ll_sz.setBackgroundColor(getResources().getColor(R.color.white));
        ll_xs.setBackgroundColor(getResources().getColor(R.color.white));
        tv_xs.setTextColor(getResources().getColor(R.color.text_nor));
        iv_xs.setImageResource(R.drawable.icon_cd_go_nor);
        tv_bb.setTextColor(getResources().getColor(R.color.text_nor));
        iv_bb.setImageResource(R.drawable.icon_cd_go_nor);
        tv_yw.setTextColor(getResources().getColor(R.color.text_nor));
        iv_yw.setImageResource(R.drawable.icon_cd_go_nor);
        tv_th.setTextColor(getResources().getColor(R.color.text_nor));
        iv_th.setImageResource(R.drawable.icon_cd_go_nor);
        tv_hy.setTextColor(getResources().getColor(R.color.text_nor));
        iv_hy.setImageResource(R.drawable.icon_cd_go_nor);
        tv_sz.setTextColor(getResources().getColor(R.color.text_nor));
        iv_sz.setImageResource(R.drawable.icon_cd_go_nor);
    }


    private void init(String type) {
        //图标

        int icon[] = {R.drawable.icon_cd_bb_mdjy, R.drawable.icon_cd_yw_xsdd, R.drawable.icon_cd_yw_sspd,
                R.drawable.icon_cd_bb_kccx, R.drawable.icon_cd_bb_xsfl, R.drawable.icon_cd_bb_kccx,
                R.drawable.icon_cd_bb_mdjy, R.drawable.icon_cd_bb_spph,
                R.drawable.icon_cd_bb_xsfl, R.drawable.icon_cd_bb_khwl, R.drawable.icon_cd_bb_ywywl,
                R.drawable.icon_cd_bb_xsfl, R.drawable.icon_cd_bb_kccx,
                R.drawable.icon_cd_bb_mdjy, R.drawable.icon_cd_bb_spph, R.drawable.icon_cd_bb_spph,
                R.drawable.icon_cd_bb_xsfl, R.drawable.icon_cd_bb_kccx, R.drawable.icon_cd_bb_kccx,
                R.drawable.icon_cd_bb_spph, R.drawable.icon_cd_bb_spph
        };
        String name2[] = {"收银报表", "销售汇总", "收款汇总", "销售小票", "销售明细", "库存查询", "门店经营", "商品排行",
                "销售分类", "客户往来", "业务员往来", "采购明细", "调拨明细", "配送明细", "盘点明细", "进销存明细",
                "售价调整商品", "促销价调整商品", "销售趋势", "销售对比", "收银员对比"};

        //图标下的文字
        int icno[] = {R.drawable.icon_cd_yw_cgdd, R.drawable.icon_cd_yw_cgsh, R.drawable.icon_cd_yw_cgtc,
                R.drawable.icon_cd_yw_spsy, R.drawable.icon_cd_yw_dbck, R.drawable.icon_cd_yw_dbrk, R.drawable.icon_cd_yw_dbrk,
                R.drawable.icon_cd_yw_dbck, R.drawable.icon_cd_yw_dbrk, R.drawable.icon_cd_yw_dbrk,
                R.drawable.icon_cd_yw_xsdd, R.drawable.icon_cd_yw_xsck, R.drawable.icon_cd_yw_xsdd,
                R.drawable.icon_cd_yw_mdbh, R.drawable.icon_cd_yw_sspd, R.drawable.icon_cd_yw_sspd,
                R.drawable.icon_cd_yw_xsdd};
        String name[] = {
                "采购订单", "采购收货", "采购退厂",
                "商品损溢", "调拨出库",
                "调拨入库", "调拨差异单",
                "配送出库单", "配送入库单", "配送差异单",
                "销售订单", "销售出库", "销售退货",
                "门店补货", "实时盘点", "盘点单录入", "补货建议单"};

        //零售
        int icon_ls[] = {R.drawable.icon_cd_yw_dbck, R.drawable.icon_cd_yw_dbrk, R.drawable.icon_cd_yw_dbrk,
                R.drawable.icon_cd_yw_dbck, R.drawable.icon_cd_yw_sspd, R.drawable.icon_cd_yw_xsdd,R.drawable.icon_cd_yw_cgdd,
                R.drawable.icon_cd_yw_dbck, R.drawable.icon_cd_yw_spsy};
        String name_ls[] = {
                "开钱箱", "销售模式", "退货模式","练习模式",
                "会员管理", "电子秤商品","电子秤管理", "副屏图片", "修改密码"};

        String[] from = {"img", "text"};
        int[] to = {R.id.img, R.id.text};
        if (type.equals("yw")) {
            initData(icno, name);
        } else if (type.equals("bb")) {
            initData(icon, name2);
        } else {
            initData(icon_ls, name_ls);
        }

        ywadapter = new SimpleAdapter(this, dataList, R.layout.grid_item, from, to);
        gridview_main.setAdapter(ywadapter);
        gridview_main.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (dataList.get(position).get("text").toString()) {
                    case "开钱箱":
                        if (permiton.isCanKqx()) {
                            App.isAidl = true;
                            AidlUtil.getInstance().openCash();
                            new LogUtil().save(Constant.LOG_KQX);
                        } else {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                        }
                        break;
                    case "练习模式":
                        if (!permiton.isCanLx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            new AlertDialog.Builder(MenuActivity.this)
                                    .setTitle("提示")
                                    .setMessage("是否切换到练习模式，练习模式下，将不会存储订单信息")
                                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            Intent intent = new Intent(MenuActivity.this, PointActivity.class);
                                            intent.putExtra("data", Constant.LX);
                                            startActivity(intent);
                                        }
                                    }).setNegativeButton("取消", null).show();
                        }
                        break;
                    case "销售模式":
                        Intent intent = new Intent(MenuActivity.this, PointActivity.class);
                        intent.putExtra("data", "xs");
                        startActivity(intent);
                        break;
                    case "电子秤管理":
                        startActivity(new Intent(MenuActivity.this, ScaleMangerActivity.class));
                        break;
                    case "退货模式":
                        if (!permiton.isCanTh()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        new android.app.AlertDialog.Builder(MenuActivity.this)
                                .setTitle("提示")
                                .setMessage("是否切换到退货模式？")
                                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent intent = new Intent(MenuActivity.this, PointActivity.class);
                                        intent.putExtra("data", Constant.Refund);
                                        startActivity(intent);
                                    }
                                })
                                .setNegativeButton("取消", null).show();

                        break;
                    case "电子秤商品":
                        startActivity(new Intent(MenuActivity.this, ScaleGoodsActivity.class));
                        break;
                    case "会员管理":
                        startActivity(new Intent(MenuActivity.this, VipActivity.class));

                        break;
                    case "副屏图片":
                        selectPicture();
                        break;
                    case "修改密码":
                        showpwd();
                        break;
                    case "门店补货":
                        downStore();
                        if (!permiton.isMdbh()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SupGoodsListActivity.class));
                        break;
                    case "调拨出库":
                        downStore();
                        if (!permiton.isDbck()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, DboOutListActivity.class));
                        break;
                    case "调拨入库":
                        downStore();
                        if (!permiton.isDbrk()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, DboReceiveListActivity.class));
                        break;
                    case "采购订单":
                        downStore();
                        if (!permiton.isCgdd()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, CgshListActivity.class));
                        break;
                    case "采购收货":
                        downStore();
                        if (!permiton.isCgsh()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, ReceiveBillListActivity.class));
                        break;
                    case "采购退厂":
                        downStore();
                        if (!permiton.isCgtc()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, RefundBillListActivity.class));
                        break;
                    case "销售订单":
                        downStore();
                        if (!permiton.isXsdd()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SaleListActivity.class));
                        break;
                    case "销售出库":
                        downStore();
                        if (!permiton.isXsck()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, OutBillListActivity.class));
                        break;
                    case "销售退货":
                        downStore();
                        if (!permiton.isXsth()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, com.pospi.pai.yunpos.xs.RefundBillListActivity.class));
                        break;
                    case "商品损溢":
                        downStore();
                        if (!permiton.isSpsy()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, OverFlowListActivity.class));
                        break;
                    case "实时盘点":
                        downStore();
                        if (!permiton.isSspd()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, CountsListActivity.class));
                        break;
                    case "库存查询":
                        downStore();
                        if (!permiton.isKccn()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, InventorySearchActivity.class));
                        break;
                    case "门店经营":
                        downStore();
                        if (!permiton.isMdjy()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, StoreReportActivity.class));
                        break;
                    case "商品排行":
                        downStore();
                        if (!permiton.isSpph()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, GoodsReportActivity.class));
                        break;
                    case "销售分类":
                        downStore();
                        if (!permiton.isXsfl()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SaleCateReportActivity.class));
                        break;
                    case "客户往来":
                        downStore();
                        if (!permiton.isKhwl()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, KhReportActivity.class));
                        break;
                    case "业务员往来":
                        downStore();
                        if (!permiton.isYwywl()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, YWReportActivity.class));
                        break;
                    case "收银报表":
                        startActivity(new Intent(MenuActivity.this, StatisticsActivity.class));
                        break;
                    case "销售汇总":
                        downStore();
                        if (!permiton.isXshz()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SyySaleReportActivity.class));
                        break;
                    case "收款汇总":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, SyyPayReportActivity.class));
                        break;
                    case "销售小票":
                        downStore();
                        if (!permiton.isSkhz()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SyyOrderReportActivity.class));
                        break;
                    case "销售明细":
                        downStore();
                        if (!permiton.isXsmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SyyGoodsReportActivity.class));
                        break;
                    case "调拨差异单":
                        downStore();
//                        if (!permiton.isDbcy()) {
//                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
//                            return;
//                        }
                        startActivity(new Intent(MenuActivity.this, DboChaYListActivity.class));
                        break;
                    case "配送差异单":
                        downStore();
//                        if (!permiton.isPscy()) {
//                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
//                            return;
//                        }
                        startActivity(new Intent(MenuActivity.this, PsChaYListActivity.class));
                        break;
                    case "配送入库单":
                        downStore();
                        if (!permiton.isMdbh()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, PsReceiveListActivity.class));
                        break;
                    case "配送出库单":
                        downStore();
                        if (!permiton.isPsck()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, PsOutListActivity.class));
                        break;
                    case "盘点单录入":
                        downStore();
                        if (!permiton.isPdlr()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, PdListActivity.class));
                        break;
                    case "补货建议单":
                        downStore();
                        if (!permiton.isBhjy()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, SupAotoListActivity.class));
                        break;
                    case "采购明细":
                        downStore();
                        if (!permiton.isCgmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, CgGoodsReportActivity.class));
                        break;
                    case "调拨明细":
                        downStore();
                        if (!permiton.isDbmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, DbGoodsReportActivity.class));
                        break;
                    case "盘点明细":
                        downStore();
                        if (!permiton.isPdmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, PdGoodsReportActivity.class));
                        break;
                    case "配送明细":
                        downStore();
                        if (!permiton.isPsmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, PsGoodsReportActivity.class));
                        break;
                    case "进销存明细":
                        downStore();
                        if (!permiton.isJxcmx()) {
                            Toast.makeText(MenuActivity.this, Constant.PERMITION_TOAST, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        startActivity(new Intent(MenuActivity.this, JxcReportActivity.class));
                        break;
                    case "售价调整商品":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, LsjChangeActivity.class));
                        break;
                    case "促销价调整商品":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, PopChangeActivity.class));
                        break;
                    case "销售趋势":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, XsChartReportActivity.class));
                        break;
                    case "销售对比":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, XsPiReportActivity.class));
                        break;
                    case "收银员对比":
                        downStore();
                        startActivity(new Intent(MenuActivity.this, XsColumReportActivity.class));
                        break;
                }
            }
        });
    }

    private SimpleAdapter ywadapter;
    private List<Map<String, Object>> dataList;

    private void initData(int[] icno, String[] name) {

        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < icno.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text", name[i]);
            dataList.add(map);
        }
    }

    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    closePayDialog();
                    Toast.makeText(MenuActivity.this, "更新成功", Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    closePayDialog();
                    Toast.makeText(MenuActivity.this, "请求失败：" + (String) msg.obj, Toast.LENGTH_SHORT).show();
                    break;
            }

        }
    };

    private LoadingDialog loadingDialog;

    //支付等待提示
    private void showPayDialog(String msg) {
        if (loadingDialog == null) {
            loadingDialog = new LoadingDialog(this);
            loadingDialog.setMessage(msg);
            loadingDialog.show();
        }
    }

    //关闭支付等待提示
    private void closePayDialog() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }

    private static ExecutorService singleExecutor = null;

    /**
     * 执行单线程列队执行
     */

    public void runOnQueue(Runnable runnable) {
        if (singleExecutor == null) {

            singleExecutor = Executors.newSingleThreadExecutor();
        }
        singleExecutor.submit(runnable);

    }

    /**
     * 启动图片下载线程
     */

    private void onDownLoad(final ImgeBeen been) {
        DownLoadImageService service = new DownLoadImageService(this,
                been.getUrl(),
                new ImageDownLoadCallBack() {
                    @Override
                    public void onDownLoadSuccess(File file) {
                        // 在这里执行图片保存方法
//                       //获取到下载得到的图片，进行本地保存
                        File pictureFolder = Environment.getExternalStorageDirectory();
                        //第二个参数为你想要保存的目录名称
//                        File appDir = new File(pictureFolder, "xstore");
//                        if (!appDir.exists()) {
//                            appDir.mkdirs();
//                        }
                        String fileName = been.getKey() + ".png";
                        File destFile = new File(pictureFolder, fileName);

                        //把gilde下载得到图片复制到定义好的目录中去
                        copy(file, destFile);
                    }

                    @Override
                    public void onDownLoadFailed() {
                        // 图片保存失败
                    }
                });
        //启动图片下载线程
        runOnQueue(service);
    }

    public void copy(File source, File target) {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream(source);
            fileOutputStream = new FileOutputStream(target);
            byte[] buffer = new byte[1024];
            while (fileInputStream.read(buffer) > 0) {
                fileOutputStream.write(buffer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    // 保存图片到手机指定目录
    public void savaBitmap(String imgName, byte[] bytes) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            String filePath = null;
            FileOutputStream fos = null;
            try {
                filePath = Environment.getExternalStorageDirectory().getCanonicalPath() + "/MyImg";
                File imgDir = new File(filePath);
                if (!imgDir.exists()) {
                    imgDir.mkdirs();
                }
                imgName = filePath + "/" + imgName;
                fos = new FileOutputStream(imgName);
                fos.write(bytes);
//                Toast.makeText(context, "图片已保存到" + filePath, Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (fos != null) {
                        fos.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else {
//            Toast.makeText(context, "请检查SD卡是否可用", Toast.LENGTH_SHORT).show();
        }
    }


    private void downGoods() {
        showPayDialog("商品数据较多,请耐心等待");
        Map<String, String> params = new HashMap<>();
        params.put("logid", SPHelper.getInstance().getString(Constant.USER_ID));
        params.put("sysid", SPHelper.getInstance().getString(Constant.SYS_ID));
        params.put("model", "base.mgoodsbase");
        params.put("table", "base_goodsbase");
        params.put("fun", "find");
        params.put("page", "");
        params.put("limit", "");
        new HttpConnection().postNet(params, new HttpCallBackListener() {
            @Override
            public void CallBack(final String Response) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        saveGoods(Response);
                    }
                }).start();
            }
        });
    }

    private void saveGoods(String response) {
        GoodsDao goodsDao = new GoodsDao(getApplicationContext());
        final List<GoodsDto> dtos = new ArrayList<>();
        try {
            JSONObject object = new JSONObject(response);
            String msg = object.getString("errMsg");
            String code = object.getString("errCode");
            if (!code.equals("100")) {
                Message message = Message.obtain();
                message.what = 2;
                message.obj = msg;
                handler.sendMessage(message);
            } else {
                JSONArray goodsJson = object.getJSONArray("result");
                for (int i = 0; i < goodsJson.length(); i++) {
                    GoodsDto dto = new GoodsDto();
                    JSONObject data = goodsJson.getJSONObject(i);
                    dto.setSid(data.getString("id"));//商品id
                    dto.setName(data.getString("name"));//商品名
                    dto.setPrice(Double.parseDouble(data.getString("lsj")));//零售价
                    dto.setCode(data.getString("barcode"));//商品条码
                    dto.setCategory_sid(data.getString("catid"));//分类
                    dto.setUnit(data.getString("unit"));//单位
                    dto.setSpecification(data.getString("spec"));//规格
                    dto.setDzc(data.getString("dzc"));//电子称
                    dto.setOldPrice(Double.parseDouble(data.getString("lsj")));

                    dto.setHyj(Double.parseDouble(data.getString("hyj")));
                    dto.setHyj1(Double.parseDouble(data.getString("hyj1")));
                    dto.setHyj2(Double.parseDouble(data.getString("hyj2")));
                    dto.setHyj3(Double.parseDouble(data.getString("hyj3")));
                    dto.setMinzkl(Double.parseDouble(data.getString("minzkl")));
                    dto.setUsejf(data.getString("hyjf"));
                    dto.setUsezk(data.getString("hyzk"));
                    dto.setPlu(data.getString("plu"));//电子秤商品码
                    Log.i("data", data.getString("hyjf") + "-----" + data.getString("hyzk"));


                    dtos.add(dto);
                }
                goodsDao.addGoods(dtos);//存储商品
                Log.i("login", "商品存储成功");
                Message message = Message.obtain();
                message.what = 1;
                handler.sendMessage(message);
            }

        } catch (JSONException e) {
            e.printStackTrace();

        }
    }

    private String getVersionName() {
        // 获取packagemanager的实例
        PackageManager packageManager = getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try {
            packInfo = packageManager.getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        String version = packInfo.versionName;
        return version;
    }

    public void selectPicture() {
        try {
            Intent intent = new Intent(this, PhotoSelectorActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.putExtra("limit", 9);//number是选择图片的数量
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case 0:
                if (data != null) {
                    List<String> paths = (List<String>) data.getExtras().getSerializable("photos");//path是选择拍照或者图片的地址数组
                    //处理代码
                    if (paths != null && paths.size() > 0) {
                        SPHelper.getInstance().putString(Constant.IMG_LOCAL, new Gson().toJson(paths));
                        for (String s : paths) {
                            Log.i("img", s);
                        }
                        new SumiUtil(MenuActivity.this).clear();
                    }

                }
                break;
            default:
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private String getSN() {
        String sn = "";
        try {
            Class c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            Log.i("sunmi", "the sn:" + (String) get.invoke(c, "ro.serialno"));
            sn = (String) get.invoke(c, "ro.serialno");
//            Log.i("sunmi", "First four characters:"
//                    + (String) get.invoke(c, "ro.serialno").substring(0, 4));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sn;
    }

    private String getAndroidId() {
        String m_szAndroidID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
        return m_szAndroidID;
    }

    private void showyl() {
        new CircleDialog.Builder(this)
                .setBodyView(R.layout.yl_dialog, new OnCreateBodyViewListener() {
                    @Override
                    public void onCreateBodyView(View view) {
                        et_sh_code = view.findViewById(R.id.et_goods_num);
                        et_zd_code = view.findViewById(R.id.et_goods_dj);
                        et_zd_code.setText(SPHelper.getInstance().getString(UnionConfig.TERMINALCODE, ""));
                        et_sh_code.setText(SPHelper.getInstance().getString(UnionConfig.MERCHANTCODE, ""));
                    }
                })
                .setWidth(0.5f)
                .setPositive("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        tv_merchantCode.setText("商户号：" + et_sh_code.getText().toString().trim());
                        tv_terminalCode.setText("终端号：" + et_zd_code.getText().toString().trim());
                        SPHelper.getInstance().putString(UnionConfig.MERCHANTCODE, et_sh_code.getText().toString().trim());
                        SPHelper.getInstance().putString(UnionConfig.TERMINALCODE, et_zd_code.getText().toString().trim());
                    }
                })
                .setCancelable(false)
                .setTitle("银联账号")
                .setNegative("取消", null)
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        hideSoftInput();
                    }
                })
                .show();
    }

    private void showdzc() {
        new CircleDialog.Builder(this)
                .setBodyView(R.layout.dialog_dzc_gl, new OnCreateBodyViewListener() {
                    @Override
                    public void onCreateBodyView(View view) {
                        et_num = view.findViewById(R.id.et_num);
                        et_name = view.findViewById(R.id.et_name);
                        et_ip = view.findViewById(R.id.et_ip);
                        et_xh = view.findViewById(R.id.et_xh);
                        et_num.setText(SPHelper.getInstance().getString(Constant.DZC_NUM, ""));
                        et_name.setText(SPHelper.getInstance().getString(Constant.DZC_NAME, ""));
                        et_ip.setText(SPHelper.getInstance().getString(Constant.DZC_IP, ""));
                        et_xh.setText(SPHelper.getInstance().getString(Constant.DZC_XH, ""));
                    }
                })
                .setWidth(0.5f)
                .setPositive("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        tv_dzc_num.setText("编号：" + et_num.getText().toString().trim());
                        tv_dzc_name.setText("名称：" + et_name.getText().toString().trim());
                        tv_dzc_ip.setText("IP：" + et_ip.getText().toString().trim());
                        tv_dzc_xh.setText("型号：" + et_xh.getText().toString().trim());
                        SPHelper.getInstance().putString(Constant.DZC_NUM, et_num.getText().toString().trim());
                        SPHelper.getInstance().putString(Constant.DZC_NAME, et_name.getText().toString().trim());
                        SPHelper.getInstance().putString(Constant.DZC_IP, et_ip.getText().toString().trim());
                        SPHelper.getInstance().putString(Constant.DZC_XH, et_xh.getText().toString().trim());
                        saveDzc(et_num.getText().toString().trim(), et_name.getText().toString().trim()
                                , et_ip.getText().toString().trim(), et_xh.getText().toString().trim());
                    }
                })
                .setCancelable(false)
                .setTitle("电子秤管理")
                .setNegative("取消", null)
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        hideSoftInput();
                    }
                })
                .show();
    }
    private void showpwd() {
        new CircleDialog.Builder(this)
                .setBodyView(R.layout.dialog_pwd_gl, new OnCreateBodyViewListener() {
                    @Override
                    public void onCreateBodyView(View view) {
                        et_old_pwd = view.findViewById(R.id.et_num);
                        et_new_pwd = view.findViewById(R.id.et_name);
                        et_new2_pwd = view.findViewById(R.id.et_ip);
                    }
                })
                .setWidth(0.5f)
                .setPositive("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String old = et_old_pwd.getText().toString().trim();
                        String newpwd = et_old_pwd.getText().toString().trim();
                        String new2pwd = et_old_pwd.getText().toString().trim();
                        savepwd(old, newpwd, new2pwd);
                    }
                })
                .setCancelable(false)
                .setTitle("修改密码")
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        hideSoftInput();
                    }
                })
                .setNegative("取消", null)
                .show();
    }

    private void savepwd(String old, String newpwd, String new2pwd) {
        showLodingDialog();
        Map<String, String> params = new HashMap<>();
        params.put("logid", SPHelper.getInstance().getString(Constant.USER_ID));
        params.put("sysid", SPHelper.getInstance().getString(Constant.SYS_ID));
        params.put("model", "system.muser");
        params.put("fun", "modifypwd");
        JSONObject object = new JSONObject();
        try {
            object.put("oldpwd", old);
            object.put("newpwd1", newpwd);
            object.put("newpwd2", new2pwd);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        params.put("pds", object.toString());
        new HttpConnection().postNet(params, new HttpCallBackListener() {
            @Override
            public void CallBack(final String Response) {
                closeLodindDialog();
                Log.i("result", Response);
                try {
                    JSONObject jsonObject = new JSONObject(Response);
                    String errCode = jsonObject.getString("errCode");
                    final String errMsg = jsonObject.getString("errMsg");
                    printMsg(errMsg);
                } catch (JSONException e) {
                    e.printStackTrace();
                    printMsg("修改失败!");
                }

            }
        });
    }


    private void saveDzc(String num, String name, String ip, String xh) {
        Map<String, String> params = new HashMap<>();
        params.put("logid", SPHelper.getInstance().getString(Constant.USER_ID));
        params.put("sysid", SPHelper.getInstance().getString(Constant.SYS_ID));
        params.put("model", "bill.mpossell");
        params.put("fun", "save_dzc");
        JSONObject object = new JSONObject();
        try {
            object.put("num", num);
            object.put("name", name);
            object.put("ip", ip);
            object.put("xh", xh);
            object.put("market", SPHelper.getInstance().getString(Constant.STORE_ID));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new HttpConnection().postNet(params, new HttpCallBackListener() {
            @Override
            public void CallBack(final String Response) {
                Log.i("result", Response);
            }
        });
    }

    //下载门店
    private void downStore() {
        Map<String,String> params = new HashMap<>();
        params.put("logid", SPHelper.getInstance().getString(Constant.USER_ID));
        params.put("sysid", SPHelper.getInstance().getString(Constant.SYS_ID));
        params.put("model", "base.mselect");
        params.put("fun", "getlastmarket");
        Log.i("goods", params.toString());
        new HttpConnection().postNet(params, new HttpCallBackListener() {
            @Override
            public void CallBack(String Response) {
                Log.i("login",Response);
                try {
                    JSONObject jsonObject = new JSONObject(Response);
                    JSONArray result = jsonObject.getJSONArray("result");
                    SPHelper.getInstance().putString(Constant.STORE_LIST, result.toString());
                } catch (JSONException e) {

                    e.printStackTrace();
                }
            }
        });


    }

}
